package com.nf.health.app.adapter;

import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.SectionIndexer;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.BillVo;
import com.nf.health.app.models.RegimenContent;
import com.nf.health.app.utils.ImageLoaderUtils;
import com.nf.health.app.utils.Util;

import java.util.List;

public class BillAdapter extends BaseAdapter{
	List<BillVo> newsList;
	Activity activity;
	LayoutInflater inflater = null;
	public BillAdapter(Activity activity, List<BillVo> newsList) {
		this.activity = activity;
		this.newsList = newsList;
		inflater = LayoutInflater.from(activity);
	}
	@Override
	public int getCount() {
		return newsList == null ? 0 : newsList.size();
	}

	@Override
	public Object getItem(int position) {
		if (newsList != null && newsList.size() != 0) {
			return newsList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		BillVo item = newsList.get(position);
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_bill, position);
		if(item.getScore().contains("-")){
			holder.setText(R.id.jia_bill_money, item.getScore());
			holder.getView(R.id.jian_bill_money).setVisibility(View.INVISIBLE);
			holder.getView(R.id.jia_bill_money).setVisibility(View.VISIBLE);
		}else{
			holder.setText(R.id.jian_bill_money, "+" + item.getScore());
			holder.getView(R.id.jian_bill_money).setVisibility(View.VISIBLE);
			holder.getView(R.id.jia_bill_money).setVisibility(View.INVISIBLE);
		}
		holder.setText(R.id.bill_name, item.getSource());
		holder.setText(R.id.bill_time, Util.timeStampDate(item.getCreatetime(), "yyyy-MM-dd"));
		return holder.getConvertView();
	}
}